package com.ssm.reactive.controller;

import com.ssm.reactive.domain.Employee;
import com.ssm.reactive.repository.IEmployeeRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import static org.springframework.web.reactive.function.server.ServerResponse.ok;

@Configuration(proxyBeanMethods = false)
public class RouterFunctionController {
    @Bean
    RouterFunction<ServerResponse> routerFunction(IEmployeeRepository er) {
        return route()
                .GET("employees", serverRequest -> ok().body(er.findAll(), Employee.class))
                .build();
    }
}
